/*
 * XXX
 */

package edu.uhcl.csci4838.group3.date;

/**
 * XXX
 * 
 * @author Chris Waguespack
 */
public class SimpleTime {
	private int hour;
	private int minute;
	
	
	
	/**
	 * XXX
	 * 
	 * @return
	 */
	/* 
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		int stdHour = this.hour;
		String meridiem = "AM";
		
		// Adjust the hour
		if (this.hour == 0) {
			stdHour = 12;
		} else if (this.hour > 12) {
			stdHour -=12;
		}
		
		// Get the meridiem
		if (this.hour > 11) {
			meridiem = "PM";
		}
		
		// Return string based on minute
		if (minute < 10) {
			return "" + stdHour + ":0" + minute + " " + meridiem;
		} else {
			return "" + stdHour + ":" + minute + " " + meridiem;
		}
	}
	
	public String toMilitaryTimeString() {
		if (minute < 10) {
			return "" + hour + ":0" + minute;
		} else {
			return "" + hour + ":" + minute;
		}
	}

	/**
	 * XXX
	 */
	public SimpleTime() {
		this(0,
				0);
	}
	
	/**
	 * XXX
	 * 
	 * @param hour
	 * @param minute
	 */
	public SimpleTime(final int hour,
			final int minute) {
		super();
		this.hour = hour;
		this.minute = minute;
	}
	
	/**
	 * Returns XXX.
	 * 
	 * @return XXX
	 * @see #setXXX
	 */
	public int getHour() {
		return this.hour;
	}
	
	/**
	 * Returns XXX.
	 * 
	 * @return XXX
	 * @see #setXXX
	 */
	public int getMinute() {
		return this.minute;
	}
	
	/**
	 * Sets XXX.
	 * 
	 * @param hour
	 *            XXX
	 * @see #getXXX
	 */
	public void setHour(final int hour) {
		if ((this.hour < 0)
				|| (this.hour > 23)) {
			throw new IllegalArgumentException("Invalid number of hours!");
		}
		
		this.hour = hour;
	}
	
	/**
	 * Sets XXX.
	 * 
	 * @param minute
	 *            XXX
	 * @see #getXXX
	 */
	public void setMinute(final int minute) {
		if ((this.minute < 0)
				|| (this.minute > 59)) {
			throw new IllegalArgumentException("Invalid number of minutes!");
		}
		
		this.minute = minute;
	}
}
